import 'package:flutter/material.dart';
import 'package:common_utils/common_utils.dart';
import 'package:xinxuan/common/button_util.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:xinxuan/common/dialogs/del_dialog.dart';
import 'package:xinxuan/utils/color_util.dart';
import 'package:get/get.dart';

class BlindBoxOrderBtns extends StatelessWidget {

  final String voucherCode;
  final int status;
  /// 转提货
  final Function conversionPickingFun;
  /// 提货码
  final Function pickUpCodeFun;
  /// 查看提货码
  final Function seePickUpCodeFun;
  /// 核销
  final Function checkoff;
  /// 是否核销员
  final int isWriteoffOfficer;
  final int type;

  BlindBoxOrderBtns({
    required this.voucherCode,
    required this.status,
    required this.conversionPickingFun,
    required this.pickUpCodeFun,
    required this.seePickUpCodeFun,
    required this.checkoff,
    required this.isWriteoffOfficer,
    required this.type
  });

  @override
  Widget build(BuildContext context) {
    List<Widget> widgets = [];
    if (isWriteoffOfficer == 1 && type == 2 && status != 10) {
      widgets = [
        Container(
          width: 90.w,
          margin: EdgeInsets.only(left: 12.w),
          child: ButtonUtil(
            text: '核销', 
            fontSize: 14.sp, 
            borderRadius: 18.w, 
            height: 36.h, 
            onTop: () {
              Get.dialog(DelDialog(message: '确认核销吗？', onTap: () async {
                checkoff();
              }));
            }
          ),
        )
      ];
    } else {
      if (status == 2 && TextUtil.isEmpty(voucherCode)) {
        widgets = [
          Container(
            width: 90.w,
            margin: EdgeInsets.only(left: 12.w),
            child: ButtonUtil(
              text: '转提货', 
              fontSize: 14.sp, 
              borderRadius: 18.w, 
              textColor: mainTextColor,
              height: 36.h, 
              showBorder: true,
              bgColors: [
                bgWhiteColor,
                bgWhiteColor,
              ],
              onTop: () {
                conversionPickingFun();
              }
            )
          ),
          Container(
            width: 90.w,
            margin: EdgeInsets.only(left: 12.w),
            child: ButtonUtil(
              text: '提货码', 
              fontSize: 14.sp, 
              borderRadius: 18.w, 
              height: 36.h, 
              onTop: () {
                pickUpCodeFun();
              }
            ),
          )
        ];
      } else if (status == 2 && !TextUtil.isEmpty(voucherCode)) {
        widgets = [
          Container(
            width: 90.w,
            margin: EdgeInsets.only(left: 12.w),
            child: ButtonUtil(
              text: '查看提货码', 
              fontSize: 14.sp, 
              borderRadius: 18.w, 
              height: 36.h, 
              onTop: () {
                seePickUpCodeFun();
              }
            ),
          )
        ];
      } else {
        return Container();
      }
    }
    return Row(
      mainAxisAlignment: MainAxisAlignment.end,
      children: widgets,
    );
  }
}